const joi = require("joi")

let _id = joi.string().required().error(new Error('_id为必填项'))
let parentid = joi.string().required().error(new Error('parentid为必填项'))
let type = joi.string().required().error(new Error("菜单类型为必填项且必须为"))
let icon = joi.string().error(new Error("图标格式不正确"))
let name = joi.string().min(2).max(12).required().error(new Error("名称为必填项且长度为2-12个字符"))
let path = joi.string().required().error(new Error("路由地址为必填项"))
let component = joi.string().required().error(new Error("组件路径为必填项"))
let permission = joi.string().error(new Error("权限标识为字符串"))
let sort = joi.number().error(new Error("排序为数值类型且必填项"))
let link = joi.boolean().error(new Error("外链格式不正确"))
let status = joi.boolean().required().error(new Error("状态格式不正确"))
let cache = joi.boolean().error(new Error("缓存格式不正确"))
const MenuSchema = {
    Directory: joi.object({ parentid, type, name, sort, status, icon, }), // 目录验证
    Menu: joi.object({ parentid, type, name, sort, component, path, status, icon, link, cache }),
    Button: joi.object({ parentid, type, name, sort, permission, }),
}

module.exports = MenuSchema